package com.tungse.juc.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Demo2 {
    public static void main(String[] args) {
        Phone1 phone = new Phone1();
        new Thread(()->{
            phone.sms();
        },"A").start();

        new Thread(()->{
            phone.sms();
        },"B").start();
    }
}

class Phone1 {
    Lock lock = new ReentrantLock();
    public void sms() {
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName() + "  sms");
            call();
        } finally {
            lock.unlock();
        }
    }
    public synchronized void call() {
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName() + "  call");
        } finally {
            lock.unlock();
        }
    }
}